# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        i1, i2 = head, head
        while i1 and i2:
            try:
                i1 = i1.next
                i2 = i2.next.next
                if i1 is i2:
                    return True
            except:
                break
        return False
